﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Frame.Lib.Core.Base;
using Frame.Lib.Utilities;

namespace Frame.Lib.Core.Tree.Dir
{
    class DirDAL:BaseDAL
    {
        private string _tableName;
        public DirDAL(string tableName)            
        {
            _tableName = tableName.ToString();
        }

        public Dictionary<int, int> GetCreatorIDs(List<int> ids)
        {
            string strIDs = ConvertUtil.ConvertToDbStr(ids);
            string strSql = "select ID,CreatorID from " + _tableName + " where ID in (" + strIDs + ")";
            DataTable dt = dbOper.Query(strSql);
            Dictionary<int, int> ditCreatorIDs = new Dictionary<int, int>();
            foreach (DataRow dr in dt.Rows)
            {
                ditCreatorIDs.Add((int)dr["ID"], (int)dr["CreatorID"]);
            }
            return ditCreatorIDs;
        }

        internal DataTable GetDataTable(object upperID)
        {
            string strSql = "select a.*,b.[ID] as UserID from " + _tableName + " a left join " + STableName.User + " b on a.CreatorID = b.ID where upperID=" + upperID;
            
            strSql += " order by a.Orders";
           
            DataTable dt = dbOper.Query(strSql);
            return dt;
        }
    }
}
